package cn.tedu.net.thread;
/*多线程案例实践
* 4个售票窗口,总计卖100张票
* */
public class Test3_SaleTickets1 {
    public static void main(String[] args) {
    TicketTheard t1=new TicketTheard();
    TicketTheard t2=new TicketTheard();
    TicketTheard t3=new TicketTheard();
    TicketTheard t4=new TicketTheard();
        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}
class TicketTheard extends Thread{
    static int tickets=100;
    @Override
    public void run() {
        while (1==1){
            try {
                /*问题2:超卖*/
                /*问题3:重卖*/
                //让程序休眠10ms
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(getName()+"="+tickets--);
            //判断票
            if(tickets<=0){
                break;
            }
        }
    }

    public TicketTheard() {
    }

    public TicketTheard(Runnable target) {
        super(target);
    }

    public TicketTheard(ThreadGroup group, Runnable target) {
        super(group, target);
    }

    public TicketTheard(String name) {
        super(name);
    }

    public TicketTheard(ThreadGroup group, String name) {
        super(group, name);
    }

    public TicketTheard(Runnable target, String name) {
        super(target, name);
    }

    public TicketTheard(ThreadGroup group, Runnable target, String name) {
        super(group, target, name);
    }

    public TicketTheard(ThreadGroup group, Runnable target, String name, long stackSize) {
        super(group, target, name, stackSize);
    }
}